package com.cet.programmercarl.algorithmperformancanalysis.链表;

/**
 * @program: algorithm
 * @description: 链表节点两两交换
 * @author: 陈恩涛
 * @create: 2022-03-11 17:53
 **/
public class LC24 {
    public static ListNode swapPairs(ListNode head) {
        ListNode dummy = new ListNode();
        dummy.next = head;
        ListNode current = head;
        ListNode pre = dummy;

        while (current != null && current.next != null) {
            pre.next = current.next;
            current.next = current.next.next;
            pre.next.next = current;
            pre = current;
            current = current.next;
        }

        return dummy.next;
    }
}
